package com.zzy.mq;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class Sender {

    // spring boot 为我们提供的包装类
    @Autowired
    private AmqpTemplate rabbitTemplate;

    public void send() {
        String context = "hello " + new Date();
        System.out.println("Sender类 发送消息: " + context);
        // 调用 发送消息的方法
        rabbitTemplate.convertAndSend("zzy-mq", context);
    }

    public void send(String msg) {
        System.out.println("Sender类 发送带参数的消息: " + msg);
        // 调用 发送消息的方法
        rabbitTemplate.convertAndSend("zzy-mq", msg);
    }

}
